﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

using LEEAAttendanceControl.Web;
using LEEAAttendanceControl.Codes;
using LEEAAttendanceControl.Web.Services;
using System.ServiceModel.DomainServices.Client;
using System.ComponentModel.DataAnnotations;

namespace LEEAAttendanceControl.Views
{
    public partial class NewPunch : ChildWindow
    {
        LEEAContext context = new LEEAContext();

        Attendance attendance = new Attendance();

        List<PunchType> types = new List<PunchType>()
            {
                new PunchType() { Name = "IN" },
                new PunchType() { Name = "OUT" },
                new PunchType() { Name = "BREAK" }
            };

        public NewPunch()
        {
            InitializeComponent();

            TypeCombo.ItemsSource = types;
        }

        public void LoadData(int empID)
        {
            attendance.EmployeeID = empID;

            context.Attendances.Add(attendance);

            DataContext = attendance;
        }

        private void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            context.SubmitChanges(OnChangedSubmitted, null);
        }

        protected void OnChangedSubmitted(SubmitOperation so)
        {
            if (so.HasError)
            {
                so.MarkErrorAsHandled();
            }
            else
            {
                MessageBox.Show(ApplicationStrings.GeneralSave, ApplicationStrings.GeneralSave, MessageBoxButton.OK);
                this.Close();
            }
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }
    }
}

